//
// Description: 1015. 摘花生
// Created by Loading on 2022/7/12.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 110;

// dp[i][j] 表示到 (i,j) 位置时，能够摘得的最多花生
int dp[N][N];

int main() {
    int T;
    cin >> T;

    while (T--) {
        int R, C;
        cin >> R >> C;
        int a[R][C];
        for (int i = 0; i < R; ++i) {
            for (int j = 0; j < C; ++j) {
                cin >> a[i][j];
            }
        }

        memset(dp, 0, sizeof dp);

        for (int i = 1; i <= R; ++i) {
            for (int j = 1; j <= C; ++j) {
                // 由左边和上边最大值进行状态转移
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i - 1][j - 1];
            }
        }

        cout << dp[R][C] << endl;
    }

    return 0;
}